package com.cjm.one.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.custom.entity.CustomAddress;
import com.cjm.one.service.CustomerAddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Tag(name = "用户收货地址", description = "用户收货地址")
@RequestMapping("/api/customer/address")
public class CustomerAddressController {

    @Resource
    private CustomerAddressService customerAddressService;

    @GetMapping("/list")
    @Operation(summary = "地址列表")
    public Result<Page<CustomAddress>> list(@RequestParam(name = "current",defaultValue = "1") Integer current ,
                                            @RequestParam(name = "size",defaultValue = "10") Integer size){
        return customerAddressService.list(current,size);

    }
    @PostMapping("/add")
    @Operation(summary = "添加地址")
    public Result<Boolean> add(@RequestBody CustomAddress customAddress){
        return customerAddressService.add(customAddress);

    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除地址")
    public Result<Boolean> delete(@PathVariable Long id){
        return customerAddressService.delete(id);
    }

    @PostMapping("/update")
    @Operation(summary = "更新地址")
    public Result<Boolean> update(@RequestBody CustomAddress customAddress){
        return customerAddressService.update(customAddress);
    }
    @GetMapping("/info/{id}")
    @Operation(summary = "获取地址")
    public Result<CustomAddress> getAddressInfo(@PathVariable Long id){
            return customerAddressService.getById(id);
    }
    @GetMapping("/info/default")
    @Operation(summary = "获取地址详情")
    public Result<CustomAddress> getAddressDefaultInfo(){
        return customerAddressService.getAddressDefaultInfo();
    }

}
